package com.liy.framework.web.spring.service.impl;

import com.liy.framework.common.dao.IBaseDao;
import com.liy.framework.common.vo.PageVO;
import com.liy.framework.web.spring.service.IBaseService;

import java.io.Serializable;
import java.util.List;

public abstract class BaseServiceImpl<T, PK extends Serializable> implements IBaseService<T, PK> {

    public BaseServiceImpl() {}

    public abstract IBaseDao<T, PK> getDao();

    public int add(T t) throws Exception {
        return this.getDao().insertSelective(t);
    }

    public int update(T t) throws Exception {
        return this.getDao().updateByPrimaryKeySelective(t);
    }

    public void delete(PK id) throws Exception {
        this.getDao().deleteByPrimaryKey(id);
    }

    public T findById(PK id) throws Exception {
        return this.getDao().selectByPrimaryKey(id);
    }

    public List<T> findList(T t) throws Exception {
        return this.getDao().selectList(t);
    }

    public List<T> findByPage(T t, PageVO<T> page) throws Exception {
        return this.getDao().selectByPage(t, page);
    }
}
